package com.david.appletree

import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView

class AutoSizeTextView: AppCompatTextView {
    constructor(context: Context) : super(context)
    constructor(context: Context, attr:AttributeSet) : super(context, attr)
    //
    private var customSize = 26F
    override fun setText(text: CharSequence?, type: BufferType?) {
        if (text is String) {
            while (paint.measureText(text) > measuredWidth) {
                customSize -= 1
                paint.textSize = customSize
            }
        }
        super.setText(text, type)
    }
}